local DataMgr = class("DataMgr");
local LoginData = require(SCRIPTS_DIR .. ".datas.LoginData");
local BattleData = require(SCRIPTS_DIR .. ".datas.BattleData");
function DataMgr:ctor()
    self.loginData = LoginData.new();
    self.battleData = BattleData.new();
    self:registerProtoMsg();
    self:registerHttpMsg();
    mgrs.event:addEventListener(enums.Event.TipsTouchBegan,function()
        self.loginData:reset();
    end)
end

function DataMgr:getLoginData()
    return self.loginData;
end

function DataMgr:getBattleData()
    return self.battleData;
end


function DataMgr:registerProtoMsg()
    --websocket
    --[[
	mgrs.proto:registerMsg(Protocol.A2C_ROLE_BASE_INFO,handler(self,self.roleBaseInfo)); --112
    mgrs.proto:registerMsg(Protocol.A2C_SERVER_CONFIG,handler(self,self.serverConfig)); --108
    mgrs.proto:registerMsg(Protocol.A2C_ROOM_INFO,handler(self,self.roomInfo)); --106
    mgrs.proto:registerMsg(Protocol.A2C_ROOM_MEMBERS,handler(self,self.membersInfo)); --101
    mgrs.proto:registerMsg(Protocol.A2C_BATTLE_FRAME_SYNC,handler(self,self.battleFrameSync)); --102
    mgrs.proto:registerMsg(Protocol.A2C_ROLE_OPERATION_RESULT,handler(self,self.roleOperationResult)); --110 
	]]	
end

function DataMgr:registerHttpMsg()
    --http

end

function DataMgr:roleBaseInfo(data)
    self.loginData:parseBaseInfo(data);
end

function DataMgr:serverConfig(data)
    self.loginData:keepLive(data);
    local function IntervalCbk(dt)
        self.loginData:addSpareTime(dt);
    end;
    mgrs.scheduler:addIntervalCbk(IntervalCbk);
    mgrs.event:addEventListener(enums.Event.ServerKeepLiveEnd,function()
        mgrs.scheduler:delIntervalCbk(IntervalCbk);
    end)
end

function DataMgr:roomInfo(data)
    mgrs.log:printDebug("DataMgr:roomInfo");
    self.battleData:roomInfo(data);
end

function DataMgr:membersInfo(data)
    mgrs.log:printDebug("DataMgr:membersInfo");
    self.battleData:roomMembers(data);
end

--通知战斗事件，例如鱼的死亡，其他玩家的操作变化等。
function DataMgr:battleFrameSync(data)
    self.battleData:battleFrameSync(data);
end

function DataMgr:roleOperationResult(data)
    self.battleData:roleOperationResult(data);
end

mgrs.data = nil;
mgrs.singleClass(mgrs,DataMgr,"data");

--endregion
